package xyz.scootaloo.draft.shell

import xyz.scootaloo.draft.shell.GenericData

/**
 * @author flutterdash@qq.com
 * @since 2021/5/18 23:07
 */
class GenericData<R>(value: R) {
    private var values = arrayOfNulls<Any>(3)
    private var size = 0
    fun or(value: R): GenericData<R> {
        add(value)
        return this
    }

    private fun add(value: R) {
        if (size == values.size) {
            expandsArray()
        }
        values[size] = value
        size++
    }

    private fun expandsArray() {
        val newArray = arrayOfNulls<Any>(values.size + 3)
        System.arraycopy(values, 0, newArray, 0, values.size)
        values = newArray
    }

    init {
        add(value)
    }
}
